<?php
class EmployeeAction extends IntesysAction {
	
	function _initialize(){
        parent::_initialize();
		
		$this->dao = D('Member');// 编辑、删除操作需要
    }
	function index(){
		$this->listmap	="1";
		$this->rename	='i';
		$this->pagesize = 10;
		$this->getLevelNameList = $this->dao -> getLevelNameList();
		if($this->_get('keywords')){
			$keywords=trim($this->_param('keywords'));
			if($keywords!=''){
				if($keywords=='男'||$keywords=='女'){
					switch($keywords){
						case '男':$this->listmap .=' and i.sex = 1';break;
						case '女':$this->listmap .=' and i.sex = 0';break;
					}
				}else{
					$this->listmap .= " and (i.name like '%".$keywords."%' or i.nickname like '%".$keywords."%' or i.id = '".$keywords."'"." or i.company_id like '%".$keywords."%' or i.tel like '%".$keywords."%')";
				}
			}else{
				$this->listmap .= " and (i.name like '%".$keywords."%' or i.nickname like '%".$keywords."%' or i.id = '".$keywords."')";
			}
			$this->keywords = $this->_get('keywords'); 
		}
		
		if($this->_get('level')){
			if($this->_get('level') != 'all'){
				$this->listmap .= " and (i.level = '".$this->_get('level')."')";
			}
			$this->level = $this->_get('level');
		}
		if($this->_get('status')){
			if($this->_get('status') != '-999'){
				$this->listmap .= " and (i.status = '".$this->_get('status')."')";
			}
//			$this->level = $this->_get('level');
		}elseif($this->_get('status')==0){
			$this->listmap .= " and (i.status = '".$this->_get('status')."')";
		}
        
        /*if($this->_get('groupid')){
           $this->listmap.=" and group_id != 0 ";
        }*/
		$this->listmap.=" and i.site_id=".__SITEID__. '  ';//and pid = 0
		//不显示超级管理员的账号
		$admin=D('Member')->where('id = '.$this->memberInfo['id'])->getfield('isadministrator');
		if($admin!=1){
			$this->listmap.=" and i.isadministrator=0 ";
		}
		$this->myid=$this->memberInfo['id'];
		if($this->_param('member_position_id')&&($this->_param('member_position_id')!='')){
			foreach($this->_param('member_position_id') as $v){
				$memberpositionstr[] = "i.memberpositionid like '%,".$v.",%'";
			}
			if(count($memberpositionstr) > 0){
			    $this->listmap.=" and (".implode(' or ', $memberpositionstr).")";
		    }
		}
//		else{
//			$this->listmap.=" and i.memberpositionid <> '' ";
//		}
		$join = ' __MEMBER__ m on i.pid =m.id';
		$field='i.*,m.name as pname';
        parent::_list($this->rename,$join,$field);
		/*$list = $this->get('list');
		foreach($list as $k => $v){
		    //$list[$k]['sub'] = $this -> dao -> getListToArray1($v['id'], __SITEID__);
			$list[$k]['level'] = $this->dao->getLevelName($v['id']);
		}
		$this->assign('list', $list);*/
		$map['site_id'] = __SITEID__;
		$coupons = M('coupon')->where($map)->select();
		$this->assign("coupons",$coupons);
		
		$this->groupList=M('member_group')->where(['site_id'=>__SITEID__])->getField('id,title');
		$this->positionList=M('member_position')->where(['site_id'=>__SITEID__])->getField('id,name');
		$this->display('Employee:index');
	}

	//提醒是否有员工入职表需要审核
	public function missionCheck(){

		$total=D('Mission')->where('site_id ='.__SITEID__." and particular = 2 and state = 1 and (approver_id = ".$this->memberInfo['id']." or reviewer_id = ".$this->memberInfo['id']." or approver like '%,".$this->memberInfo['id'].",%')")->count();
		if($total>0){
			$data['error']='有'.$total.'张员工入职表未审核';
			$data['state']=1;
		}else{
			$data['state']=0;
		}
		echo json_encode($data);
	}

	public function sendCoupon(){
		$coupon_id = $this->_post('coupon_id');
		$this->ids = explode(',', $this->_post('ids'));
		$need = count($this->ids);
		import("@.ORG.Coupon.Coupon");
        $Coupon = new Coupon($coupon_id,"0");
        if($Coupon->canUse()){
        	$exist = $Coupon->exist();
        	if($need <= $exist){
        		$ret['status'] = 1;
        		$ret['info'] = null;
        		foreach($this->ids as $openid){
        			$member_map['openid'] = $openid;
        			$member_map['site_id'] = __SITEID__;
        			$member = M('member')->where($member_map)->find();
        			if($member && $result = $Coupon->getCoupon($member['id'])){
        				$msg = "赠送您一张".$Coupon->coupon['title']."优惠券，价值".
        				$Coupon->coupon['discount']."元，在商城买满".$Coupon->coupon['full']."可以使用，有效期为".
        				$Coupon->coupon['sn_expires']."天";
        				sendWXMsg($openid,$msg);
        			}else{
        				$ret['status'] = 0;
        				$ret['info'] .= "赠送用户ID为".$openid."优惠券时发生错误，赠送该用户失败<br>";
        			}
        		}
        		$ret['info'] = $ret['info'] ? $ret['info'] : "发放成功";
        	}else{
        		$ret['status'] = 0;
        		$ret['info'] = "发放数量超出优惠券数量";
        	}
        }
        echo json_encode($ret);

	    //显示发送页面
		// if($this->_post('ids')){
		// 	$this->ids = explode(',', $this->_post('ids'));
		// 	$count = 0;
		// 	foreach($this->ids as $v){
		// 		if(sendWXMsg($v, $this->_post('msg'))){
		// 			$count ++;
		// 		}
		// 	}
		// 	$ret['status'] = 1;
		// 	$ret['info'] = $count;
		// 	$ret['data'] = '';
		// 	echo json_encode($ret);
		// }
	}
	private function getMember(){
		$pid = $this->_post('id') ? $this->_post('id') : 0;
		$map['m.pid'] = $pid;
		$map['m.site_id'] = __SITEID__;
		$ret = array();
		$list = $this->dao -> where($map) ->alias('m') -> select();
		foreach($list as $k => $v){
			//查找层级
			$deep = M('Member_member') -> where(array('member_id' => $_GET['id'],'smember_id' => $v['id'])) -> getField('deep');
			$sub = $this -> dao -> where(array('pid' => $v['id'])) -> count();
			$isParent = false;
			if($sub > 0){
				$isParent = true;
			}
			$data['isParent'] = $isParent;
			$data['id'] = $v['id'];
			$data['name'] = 'ID:'.$v['id'].'　'.$v['nickname'].'　('.$v['username'].')【'.(1 + $deep).'级会员有'.$sub.'个子级】';
			$ret[] = $data;
		}
		echo json_encode($ret);
	}
	//获取表单
	public function getNewform(){
		//$this->newform=$this->dao->where('id='.$this->_get('id'))->getField('newform');
		//$this->newform=['integral'=>unserialize($this->newform)];
		$this->newform=D('Mission')->where('member_id='.$this->_get('id').' and particular=2')->getField('formtemplate');
		if($this->newform==false){
			$this->initView();
			$this->newform=D('Form') -> where(array('particular' => 2,'site_id'=>__SITEID__)) -> createTaskForm($this-> view);
		}
		$this->display();	
	}
	//设置表单
	/*public function setNewform(){
		if(IS_AJAX){
			$this->dao->where('id='.$_POST['id'])->setField('newform',serialize($_POST['integral']));
			die(json_encode(['status'=>1]));
		}	
	}*/
	public function membertree(){
		if(IS_POST){
			$this->getMember();
			exit;
		}
		$this->display();
	}
	//查看下级会员
	 function sindex(){
		$map = 'mm.member_id = '.$this->_get('id');
		$this->id = $this->_get('id');
		$this->getLevelNameList = $this->dao -> getLevelNameList();
		if($this->_get('keywords')){
			$map .= " and (m.nickname like '%".$this->_get('keywords')."%' or m.id = '".$this->_get('keywords')."')";
			$this->keywords = $this->_get('keywords');
		}
		
		if($this->_get('level')){
			if($this->_get('level') != 'all'){
				$map .= " and (mm.level = '".$this->_get('level')."')";
			}
			
			$this->level = $this->_get('level');
		}
		$this->initView();
		$db = D('Member_member'); 
		$db -> _list($this->view, $map);
		
		$this->display();
	}
	//编辑会员
	public function edit(){
		// 查找所有积分类型
		$this -> inteType = M('Integral_type') -> where(array('site_id' => __SITEID__)) -> select();
		$this->newform=D('Form')->where('particular = 2 and site_id ='.__SITEID__)->getfield('id',false);//员工入职表id
	
		//$this->group_list=M('Member_group')->where(array('site_id'=>__SITEID__))->select();
		$this->getLevelNameList = $this->dao -> getLevelNameList();
		
		//$this->role_list=M('Member_group')->alias('r')->join('left join __MEMBER_ROLE_USER__ ru ON r.id=ru.role_id and ru.user_id='.$this->_get('id')) -> where(array('r.user_id' => session(C('USER_AUTH_KEY')))) -> select();
		$this->position_list=D('Member_position')->getList(['site_id'=>__SITEID__]);
	
		
        $this->role_list=D('Member_group')-> getList2(0,0,array('site_id'=>__SITEID__));

		$this->isadmin=D('Member')->where('id = '.$this->memberInfo['id'].' and site_id = '.__SITEID__)->getfield('isadministrator');

		$this->isIntMng=in_array($this->memberInfo['id'],getManagerList())?1:0;
		
		$member_role_user = M('Member_role_user')-> where(array('user_id' => $this->_get('id'))) -> select();
		
		
		$employee = $this->dao -> where(array('site_id' => __SITEID__, 'id' => $this->_get('id'))) -> find();
		
		$memberpositionid = trim($employee['memberpositionid'],',');
		$this -> memberpostion = D('Member_position') -> where("site_id = ".__SITEID__. " and id in(".(empty($memberpositionid)?0:$memberpositionid).")") -> select();
		
		//dump($this -> memberpostion);
//		foreach($member_role_user as $k => $v){
//
//			$member_role_userid[] = $v['role_id'];
//		}
//		$this->member_role_userids = $member_role_userid;
		//dump($this->member_role_userids);
		
		
        $this->rule_list=D('Integral_rule')->alias('r')->join('left join __INTEGRAL_RULETYPE__ t on r.type_id = t.id')->where(array('r.site_id'=>__SITEID__,'t.isfix'=>1))->Field('r.*')->select();
		$this->supplierList=M('Supplier')->alias('s')->join('left join __MEMBER_SUPPLIER__ ms ON s.id=ms.supplier_id and ms.member_id='.$this->_get('id')) -> where(array('s.site_id' => __SITEID__)) -> Field('s.*,ms.member_id,ms.supplier_id') -> select();

		if ($this->_get('id')) {
			$this->status=$this->dao->where('id ='.$this->_get('id'))->getfield('status');
            $map['id'] = array(
                'eq',
                $this->_get('id')
            );
            $info = $this->dao->where($map)->find();
			
			$info['integralconfig'] =  unserialize($info['integralconfig']);
			//获取并设置详细资料的表单
			$info['newform']=D('Mission')->where('member_id='.$info['id'].' and particular=2')->getField('formtemplate');
			if($info['newform']==false){
				$this->initView();
				$info['newform']=D('Form') -> where(array('particular' => 2,'site_id'=>__SITEID__)) -> createTaskForm($this-> view);
			}
			$this->assign('info', $info);

			//是否我的下属
			$mypos=D('Member_position')->where('member_id = '.$this->memberInfo['id'])->getfield('id');
			$hispos=array_filter(explode(',',D('Member')->where('id = '.$this->_get('id'))->getfield('memberpositionid')));
			if(in_array($mypos,$hispos)){
				$this->mybelonging='1';
			}else{
				$this->mybelonging='0';
			}

			//页面显示部门
//			<span style="display:inline-block;" class="itemspan"><input type="hidden" name="edit_name[]" value="销售部"><input type="hidden" value="312" name="edit_id[]">销售部<a href="javascript:void(0);" style="color:#2F9C49; padding:0 8px;" class="">x</a></span>
			$posid=D('Member')->where('id ='.$this->_get('id'))->getfield('memberpositionid');
			$posid=array_filter(explode(',',$posid));
			foreach($posid as $k =>$v){
				$this->hiddenid.='<input type="hidden" name="member_position_id" value="'.$v.'">';
				$posname=D('Member_position')->where('id ='.$v)->getfield('name');
				$this->hiddenpos.='<span style="display:inline-block;" class="itemspan"><input type="hidden" name="edit_name[]" value="'.$posname.'"><input type="hidden" value="'.$v.'" name="edit_id[]">'.$posname.'<a href="javascript:void(0);" style="color:#2F9C49; padding:0 8px;" class="close">x</a></span>';
			}

            $this->display();
        } else {
            $this->error('参数错误');
        }

	}
	//新建会员
	public function add(){
		addDetection('Member');
		$this -> inteType = M('Integral_type') -> where(array('site_id' => __SITEID__)) -> select();
		$this->newform=D('Form')->where('particular = 2 and site_id ='.__SITEID__)->getfield('id',false);//员工入职表id
		$this->getLevelNameList = $this->dao -> getLevelNameList();
        $this->role_list=D('Member_group')-> getList2(0,0,array('site_id'=>__SITEID__));
        $this->rule_list=D('Integral_rule')->alias('r')->join('left join __INTEGRAL_RULETYPE__ t on r.type_id = t.id')->where(array('r.site_id'=>__SITEID__,'t.isfix'=>1))->Field('r.*')->select();
		parent::add();
	}
	//更新用户信息
	public function update(){
		$member_positionDB=D('Member_position');
		$member_id = $this->_post('id');
		if($this -> _post('leveldown') == 0){
			M('Member_member') -> where(array('smember_id' => $member_id)) -> data(array('level' => $this->_post('level'))) -> save();
			
		}
		$_POST['integralconfig'] = serialize($_POST['integralconfig']);
		$member_position_id = $_POST['member_position_id'];
		$_POST['memberpositionid'] =$member_position_id;
		//如果设置部门管理员为真，则设置此用户为部门管理员
//		if($this->_post('isPositionAdmin')){
//			$member_positionDB->updateManager();
//		}
        if(trim($_POST['role_id'])!=''){$_POST['group_id']=$_POST['role_id'][0];}
		if($member_id){
            if(""!=trim($_POST['password'])){
                $_POST['password']=md5($_POST['password']);    
            }else{
                unset($_POST['password']);
            }
			$_POST['status']=$_POST['sta'];
            if(isset($_POST['reg_time'])){$_POST['reg_time']=strtotime($_POST['reg_time']);}
            if(isset($_POST['role_id'])){$_POST['group_id']=$_POST['role_id'][0];}
			if(isset($_POST['role_id'])){
				$data1=$_POST;
				$role_user=M('Member_role_user');
				$role_user->where(array('user_id'=>$data1['id']))->delete();
				foreach($data1['role_id'] as $k=>$v){
					$r['user_id']=$data1['id'];
					$r['site_id']=__SITEID__;
					$r['role_id']=$v;
					if(!$role_user->add($r)){
						$flag=false;
					}
				}
				$thismanager=D('Member_group')->where('site_id ='.__SITEID__.' and ismanager = 1 ')->getField('id');//主管
				if($_POST['group_id']==$thismanager){
					D('Member_position')->setManager($member_id,$member_position_id);
				}else{
					//如果现在给的不是主管，但是以前是主管，就删除他
					$listManager=D('Member_position')->where('site_id ='.__SITEID__.' and member_id ='.$member_id)->getfield('id');
					if($listManager){
						$data['member_id']='';
						$data['member_name']='';
						D('Member_position')->where('id ='.$listManager)->data($data)->save();
					}
				}
			}
		   //写入部门名称信息
//		   $member_position_id[] = 0;
			if($_POST['member_position_id']){
				$member_position = M('Member_position') -> where("id =".$member_position_id) -> getField('name');
				$_POST['memberpositionname'] = $member_position;
			}else{
				$_POST['memberpositionname']='';
			}
		}
		addDetection('Member');
		addDetection('Admin');
		parent::update();
	}
    public function insert(){
		if($jumpUrl == ''){
			$jumpUrl = (session('jumpUrl')&&session('jumpUrl')!='') ? session('jumpUrl') : U('Employee_add/index');
		}
		if(isset($_POST)){
			if(!session(C('ADMIN_AUTH_KEY') )){
			    $_POST['pid'] = session(C('USER_AUTH_KEY'));
			}
			$_POST['site_id']=__SITEID__;
			if(isset($_POST['reg_time'])){$_POST['reg_time']=strtotime($_POST['reg_time']);}
            if(isset($_POST['role_id'])){$_POST['group_id']=$_POST['role_id'][0];}
			$_POST['password']=md5($_POST['password']);
			$_POST['username']=$_POST['tel'];
			if($_POST['member_position_id']){
				$member_position_id=$_POST['member_position_id'];
				$_POST['memberpositionid'] = $member_position_id;

				//$member_position_id = array_filter($_POST['memberpositionid']);
				//写入部门名称信息
			   $member_position = M('Member_position') -> where("id =". $member_position_id) -> getField('name');
			   $_POST['memberpositionname'] = $member_position;
			}
			$createret = $this->dao->create();
			$is_exist=M('Member')->where('site_id = '.__SITEID__.' and tel = '.$_POST['tel'])->find();
			if($is_exist){
			 $this->error('该号码已存在');
			 die();
				}
			if(!$createret){
				$this->error($this->dao -> getError());exit;
			}
			
			//当用户数量超过预定站点‘最大用户值’的时候报错
			if(!D('Site')->judgeMaxNum()){
				$this->error('警告，已达到当前站点最大用户数量！');exit;
			}
			
			
			$id = $this->dao->add();
			
			if(!$id){
				$this->error($this->dao -> getError());exit;
			}else{
				$thismanager=D('Member_group')->where('site_id ='.__SITEID__.' and ismanager = 1 ')->getField('id');
				if($_POST['group_id']==$thismanager){
					D('Member_position')->setManager($id,$member_position_id);
				}
			}
			$data=$_POST;
			$flag=true;
			$role_user=M('Member_role_user');
            $role_user->where(array('user_id'=>$id))->delete();
			
			foreach($data['role_id'] as $k=>$v){
				$r['user_id']=$id;
				$r['role_id']=$v;
				$r['site_id']=__SITEID__;
				if(!$role_user->add($r)){
					$flag=false;
				}
			}
			$integral=new Integral();
			$integral->addIntegralNum($id);
			
			if($flag){
				$this->success('添加成功',$jumpUrl);
			}else{
				$this->error('出错了,可能是数据库链接出错,请检查');
			}
			//parent::insert();
		}
		
	    addDetection('Member');
		addDetection('Admin');
	}
	public function sendMsg(){
	    //显示发送页面
		if($this->_post('ids')){
			$this->ids = explode(',', $this->_post('ids'));
			$count = 0;
			foreach($this->ids as $v){
				if(sendWXMsg($v, $this->_post('msg'))){
					$count ++;
				}
			}
			$ret['status'] = 1;
			$ret['info'] = $count;
			$ret['data'] = '';
			echo json_encode($ret);
		}
	}
	//更新父ID
	public function updatePid(){
		if($this->_post('pid')){
			$pid = $this->_post('pid');
			$member_id = $this -> _post('member_id');
			$ret = $this->dao -> updatePid($member_id, $pid);
			if($ret){
				$this->success('操作成功！');
			}else{
				$this->error('操作失败，该会员的父ID不能更改');
			}
		}else{
			$this->error('参数错误');
		}
	}
	//更新父ID
	public function deletePid(){
		if($this->_get('pid')){
			$pid = $this->_get('pid');
			$member_id = $this -> _get('member_id');
			$ret = $this->dao -> deletePid($member_id, $pid);
			if($ret){
				
				
				M('Member_member') -> where(array('site_id' => __SITEID__, 'member_id'=>$pid, 'smember_id' => $member_id )) -> delete();
				
				
				$this->success('操作成功！');
			}else{
				$this->error('操作失败，该会员的父ID不能更改');
			}
		}else{
			$this->error('参数错误');
		}
	}
	
	public function delete(){
		if(isset($_GET['id']) && intval($_GET['id'])>0){
			M('Member_member') -> where(array('site_id' => __SITEID__, 'smember_id' => $this->_get('id') )) -> delete();
		}
		parent::delete();
		
	}
	
	//添加会员积分
	public function addintegral(){
		$id = $this->_get('id');

		if(IS_POST){
		   $id = $this->_post('id');
		   $integral = $this->_post('integral');
		   import("@.ORG.Integrals.Integral");
		   $Integral = new Integral($id);
		   $mes = $Integral->giveIntegral($integral);
		   if($mes){
				$this->success('操作成功！');
				exit;
			}else{
				$this->error('操作失败');
				exit;
			}
		}
		
		$this->assign('id',$id);
		$this->display();
	}
	
	//会员直接登录
	public function login(){
		$member = $this->dao -> where(array('site_id' => __SITEID__, 'id' => $this-> _get('id'))) -> find();dump($member);
		session('memberInfo', $member);
		redirect('/'.__SITEID__.U('Member/Index/index'));
	} 

	//选择列表
	public function select(){
		$this->pagesize = 12;
		$this->listmap = "site_id = ". __SITEID__;
		$this->listmap .= " and group_id <> 0 ";
		if($this->_get('selected') && $this->_get('selected') != ''){
			$this->pagesize = 100;
			$this->listmap = "id in(".$this->_get('selected').")";
		}
		if($this->_param('keywords')){
			$keywords=$this->_param('keywords');
			$_GET['keywords']=urlencode($this->_param('keywords'));
			$this->listmap.=" and title like '%{$keywords}%'";
			$this->keywords=$keywords;
		}
		parent::_list();
		
		$list = $_GET['list'];
		$statu=$list?1:0;
		if(IS_AJAX){
			die(json_encode(array('tbody'=>$this->fetch(),'dump'=>$_REQUEST,'statu'=>$statu, 'pages' => $this->get('pages'))));	
		}else{
			$this->display();
		}
	}

	  // 导出到Excel
    public function exportExcel($expTitle, $expCellName, $expTableData)
    {
        $xlsTitle = iconv('utf-8', 'gb2312', $expTitle); // 文件名称 UTF-8有可能乱码所以转成gb
        $fileName = $_SESSION['account'] . date('_YmdHis'); // 文件名，用时间命名
        
        $cellNum = count($expCellName); // 表头
        
        $dataNum = count($expTableData); // 数据
        
        Vendor("PHPExcel.Classes.PHPExcel");
        Vendor("PHPExcel.Classes.PHPExcel.IOFactory"); // 导入PHPExcel库，少一个都不可以
        
        $objPHPExcel = new PHPExcel();
        $cellName = array(
            'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
			'AA','AB', 'AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU',
			'AV','AW','AX','AY','AZ'
        );
        
        // 字段从那里开始
        for ($i = 0; $i < $cellNum; $i ++) {
            $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i] . '1', $expCellName[$i][1]);
        }
        // 数据从那里开始
        for ($i = 0; $i < $dataNum; $i ++) {
            for ($j = 0; $j < $cellNum; $j ++) {
                $objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j] . ($i + 2), $expTableData[$i][$expCellName[$j][0]]);
            }
        }
        
        header('pragma:public');
        
        header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $xlsTitle . '.xls"');
        header("Content-Disposition:attachment;filename=$fileName.xls"); // attachment新窗口打印inline本窗口打印
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output');
        exit();
    }
    // 拿出数据导出 
     public function exportFormat()
        {
            $xlsName = "Member";
            $xlsCell = array(
			array('id','编号'),
                array(
                    'name',
                    '名称'
                ),
                array(
                    'username',
                    '账号'
                ),
                array(
                    'group_id',
                    '职位'
                ),
                array(
                    'memberpositionid',
                    '部门'
                ),
                array(
                    'tel',
                    '电话'
                ),
                array(
                    'Email',
                    '邮箱'
                ),
                array(
                    'sex',
                    '性别'
                ),
                array(
                    'Email',
                    '邮件'
                ),
                array(
                    'graduatefrom',
                    '毕业学校'
                ),
                array(
                    'address',
                    '住址'
                )
            );
            $xlsModel = M('Member');
            $xlsData = $xlsModel->where('site_id=' . __SITEID__)
                ->Field('id,name,username,tel,Email,address,sex,memberpositionid,group_id,graduatefrom')
                ->select();
            
            $groupData = M('member_group')
                ->Field('id,title')
                ->select();
            
            $positionData = M('Member_position')->where('site_id=' . __SITEID__)
                ->Field('id,name')
                ->select();

            foreach ($xlsData as $xkey => $xval) {
                
                if (! $xval[name] == '' || ! $xval[group_id] == '' || ! $xval[memberpositionid] == '') {
			
                    if ($xval[sex] == 0) {
                        $xval[sex] = "";
                    } else 
                        if ($xval[sex] == 1) {
                            $xval[sex] = "男";
                        } else {
                            $xval[sex] = "女";
                        }
                  
                    foreach ($groupData as $gkey => $gval) {
					
                        if ($xval[group_id] == $gval[id]) {
                  
                            $xval[group_id] = "";
                     
                            $xval[group_id] = $gval[title];

				
                        }
                    }
   
                    $positionid = explode(',', $xval[memberpositionid]);
                    $xval[memberpositionid] = "";
                    foreach ($positionid as $pkey => $pval) {
                        
                        foreach ($positionData as $pdkey => $pdval) {
                            if ($pval == $pdval[id]) {
                                $pval = $pdval[name];
                            }
                        }
                        
                        $xval[memberpositionid] .= $pval . "    ";
                    }
                    
                    $excel[] = $xval;
                }
            }
           
	
           	 $this->exportExcel($xlsName, $xlsCell, $excel);
        }
    }